//coins = [1, 2, 5], amount = 11
coins = [2], amount = 3
var coinChange = function (coins, amount) {
    const f = []
    f[0] = 0
    // [1 - amount] 之间的硬币总额
    for (let i = 1; i <= amount; i++) {
        f[i] = Infinity
        for (let j = 0; j < coins.length; j++) {
            // coins中有没有比i这个面额小的
            if (i - coins[j] >= 0) {
                f[i] = Math.min(f[i], f[i - coins[j]] + 1)
            }
        }
    }
    return f[amount] !== Infinity ? f[amount] : -1
}
console.log(coinChange(coins, amount));
